package com.md.api.common.utils;

import java.awt.*;
import java.awt.image.BufferedImage;

public class FontImage {


    public static BufferedImage createWatermarkImage(String text,String color) {

        String[] textArray = text.split(" ");
        Font font = new Font("仿宋", Font.PLAIN, 25);
        Integer width = 1000;
        Integer height = 500;

        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        // 背景透明 开始
        Graphics2D g = image.createGraphics();
        image = g.getDeviceConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT);
        g.dispose();
        // 背景透明 结束
        g = image.createGraphics();
        g.setColor(new Color(Integer.parseInt(color.substring(1), 16)));// 设定画笔颜色
        g.setFont(font);// 设置画笔字体
        g.shear(0.1, -0.26);// 设定倾斜度
//        设置字体平滑
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        int y = 200;
        for (int i = 0; i < textArray.length; i++) {
            g.drawString(textArray[i], 300, y);// 画出字符串
            y = y + font.getSize();
        }
        //g.drawString(DateUtils.getNowDateFormatCustom(watermark.getDateFormat()), 0, y);// 画出字符串
//        SimpleDateFormat format = new SimpleDateFormat(dateFormat);
//        g.drawString(format.format(new Date()), 0, y);// 画出字符串
        g.dispose();// 释放画笔
        return image;

    }
}
